package com.wangzeqi.neihanduanzi.welcome;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.wangzeqi.neihanduanzi.base.BaseActivity;
import com.wangzeqi.neihanduanzi.R;

import java.util.ArrayList;

/**
 * Created by dllo on 16/1/8.
 */
public class WelcomeActivity extends BaseActivity implements View.OnClickListener {
    private Handler handler;
    private ViewPager viewPager;
    private ArrayList<View> data;
    private WelcomeAdapter adapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SharedPreferences sharedPreferences = getSharedPreferences("edit", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        if (sharedPreferences.getString("count", null) != null) {
            toSecond();
        }
        editor.putString("count", "1");
        editor.commit();


        setContentView(R.layout.welcome_activity);
        viewPager = (ViewPager) findViewById(R.id.welcome_viewpager);
        data = new ArrayList<View>();

        //获取图片
        View view = getLayoutInflater().inflate(R.layout.welcome_one, null);
        data.add(view);//将图片加入到data中
        View view1 = getLayoutInflater().inflate(R.layout.welcome_two, null);
        data.add(view1);
        View view2 = getLayoutInflater().inflate(R.layout.welcome_three, null);
        data.add(view2);
        View view3 = getLayoutInflater().inflate(R.layout.welcome_four, null);
            view3.findViewById(R.id.star).setOnClickListener(this);
        data.add(view3);
        adapter = new WelcomeAdapter(data);
        //将ViewPager 与适配器绑定
        viewPager.setAdapter(adapter);
    }
    public void toSecond() {
        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }

    @Override
    public void onClick(View v) {
        toSecond();
    }
}
